package com.hxkj.cst.chengshuitong.ui.adapter

import android.content.Context
import android.content.Intent
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.LinearLayout
import android.widget.TextView
import com.hxkj.cst.chengshuitong.OrderBean
import com.hxkj.cst.chengshuitong.R
import com.hxkj.cst.chengshuitong.setDataToShared
import com.zbar.lib.CaptureActivity

/**
 * 作者：LuoYang
 * 时间：2017/6/2:14:21
 * 邮箱：18981443691@163.com
 * 说明：
 */
class OrderRecyclerItemAdapter(val orderBeans: ArrayList<OrderBean>,
                               val context: Context) : RecyclerView.Adapter<OrderRecyclerItemAdapter.ViewHolder>() {
    override fun onCreateViewHolder(parent: ViewGroup?, viewType: Int): ViewHolder {
        val view = LayoutInflater.from(context).inflate(R.layout.item_order, parent, false)
        return ViewHolder(view)
    }

    override fun getItemCount(): Int = orderBeans.size

    override fun onBindViewHolder(holder: ViewHolder?, position: Int) {
        val orderBean = orderBeans[position]
        if (holder != null) {
            with(holder) {
                mTvCjh?.append(": ${orderBean.cjh}")
                mTvCzsj?.append(": ${orderBean.czsj}")
                mTvBsdz?.append(": ${orderBean.bsdz}")
                mTvDqlc?.append(": ${orderBean.dqlc}")
                mTvZt?.append(": ${orderBean.zt}")

                mLlContain?.setOnClickListener {
                    val intent = Intent(context, CaptureActivity::class.java)
                    context.setDataToShared("location", orderBean.dqlc.toInt())
                    context.startActivity(intent)
                }

            }
        }
    }

    class ViewHolder(itemView: View?) : RecyclerView.ViewHolder(itemView) {
        var mLlContain: LinearLayout? = null
        var mTvCjh: TextView? = null
        var mTvCzsj: TextView? = null
        var mTvBsdz: TextView? = null
        var mTvDqlc: TextView? = null
        var mTvZt: TextView? = null

        init {
            mLlContain = itemView?.findViewById(R.id.io_ll_skip) as LinearLayout?

            mTvCjh = itemView?.findViewById(R.id.io_tv_cjh) as TextView?
            mTvCzsj = itemView?.findViewById(R.id.io_tv_czsj) as TextView?
            mTvBsdz = itemView?.findViewById(R.id.io_tv_bsdz) as TextView?
            mTvDqlc = itemView?.findViewById(R.id.io_tv_dqlc) as TextView?
            mTvZt = itemView?.findViewById(R.id.io_tv_zt) as TextView?
        }
    }
}